#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_drpa_dipole_h2o.info <<'%EOF%'
   Direct RPA/RCCD dipole moment, H2O Molecule
   -------------------------------------------------
   Molecule:         H2O 
   Wave Function:    dRCCD(dRPA) / aug-cc-pVDZ
   Test Purpose:     Calculate dRCCD/dRPA dipole moment
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > cc_drpa_dipole_h2o.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
H2O
Equilibrium.
Atomtypes=2 NoSymmetry
Charge=8.0 Atoms=1
O                0.0000000000  -0.1254038222    0.0000000000
Charge=1.0 Atoms=2
H                1.4298718542   0.9951266695    0.0000000000
H               -1.4298718542   0.9951266695    0.0000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_drpa_dipole_h2o.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRALS
.DIPLEN
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
*CC INP
.DRCCD
.PRINT
8
.HURWITZ
.THRENR
1.0D-10
.THRLEQ
1.0D-10
.THRVEC
1.0D-10
*CCFOP
.DIPMOM
!.NONREL
!.RLXDEN
**END OF DALTON INPUT
%EOF%
#######################################################################

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_drpa_dipole_h2o.check
cat >>cc_drpa_dipole_h2o.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Check 1: SCF Energy
CRIT1=`$GREP "Total SCF   energy:                   -76.0411249" $log | wc -l`
TEST[1]=`expr $CRIT1`
CTRL[1]=2
ERROR[1]="SCF ENERGY NOT CORRECT"

# Check 2: MP2 Energy
# TBP, May 18, 2011: removed MP2 test since gradient-based start guess
#                    is now default.
#CRIT1=`$GREP "Total MP2   energy:                   -76.2633519" $log | wc -l`
#TEST[2]=`expr $CRIT1`
TEST[2]=2
CTRL[2]=2
ERROR[2]="MP2 ENERGY NOT CORRECT"

# Check 3: SOSEX Energy
CRIT1=`$GREP "SOSEX Correlation Energy:              -0.1614041" $log | wc -l`
TEST[3]=`expr $CRIT1`
CTRL[3]=2
ERROR[3]="SOSEX CORRELATION ENERGY NOT CORRECT"

# Check 4: dRPA Energy
CRIT1=`$GREP "DRCCD Correlation Energy:              -0.2489245" $log | wc -l`
TEST[4]=`expr $CRIT1`
CTRL[4]=2
ERROR[4]="DRCCD CORRELATION ENERGY NOT CORRECT"

# Check 5: SOSEX Energy
CRIT1=`$GREP "Total SOSEX Energy:                   -76.202529" $log | wc -l`
TEST[5]=`expr $CRIT1`
CTRL[5]=2
ERROR[5]="SOSEX ENERGY NOT CORRECT"

# Check 6: dRPA Energy
CRIT1=`$GREP "Total DRCCD Energy:                   -76.290049" $log | wc -l`
TEST[6]=`expr $CRIT1`
CTRL[6]=2
ERROR[6]="DRCCD ENERGY NOT CORRECT"

# Check 7: DRCCD electronic dipole moment
CRIT1=`$GREP "y     -0.23846983        -0.60612980" $log | wc -l`
TEST[7]=`expr $CRIT1`
CTRL[7]=1
ERROR[7]="DRCCD ELECTRONIC DIPOLE MOMENT  NOT CORRECT"

# Check 8: stabilizing solution found
CRIT1=`$GREP "Solution is stabilizing" $log | wc -l`
TEST[8]=`expr $CRIT1`
CTRL[8]=1
ERROR[8]="NOT STABILIZING SOLUTION"

PASSED=1
for i in 1 2 3 4 5 6 7 8
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} )"
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################

